const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    back: '〈 我的名片',
    name: '',
    pos: '',
    company: '',
    avatarUrl: '',
    ma: '/images/ma.png',
    qr: '',
    card: '',
    imgIP: app.globalData.imgIP ,//图片IP拼接
  },
  back: function() {
    wx.navigateBack({
      // 返回第一个页面栈
      delta: 1
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    app.postData('user/search', {}, res => {
      var that = this;
      var data = res.data.data;
      this.setData({
        name: data.name,
        avatarUrl: options.avatarUrl,
        qr: that.data.imgIP + data.qr,
        card: that.data.imgIP + data.card,
      })
      console.log('首页传过来data');
      console.log(res);
    })
    var form_data = wx.getStorageSync('form');
    this.setData({
      pos: form_data.pos,
      company: form_data.company
    })
  },
  
  // 点击保存pro/card
  save: function() {
    wx.downloadFile({
      url: this.data.qr,
      success: res => {
        wx.saveImageToPhotosAlbum({
          filePath: res.tempFilePath,
          success: res => {
            wx.showModal({
              title: '存图成功'
            })
            console.log(res);
          }
        })
      }
    })
  },
 card: function () {
    var that = this;
    wx.downloadFile({
      url: that.data.card,
      success: res => {
        wx.saveImageToPhotosAlbum({
          filePath: res.tempFilePath,
          success: res => {
            wx.showModal({
              title: '保存成功'
            })
            console.log(res);
          }
        })
      }
    })
  },
show:function(){  
       this.setData({
          modal:true
       })
},
hide:function(){
  this.setData({
   modal: false
  })
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})